<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MySQL Docker 入门教程</title>
    <meta name="description" content="MySQL 是最流行的关系型数据库管理系统，在 WEB 应用方面 MySQL 是最好的 RDBMS(Relational Database Management System：关系数据库管理系统)应用软件之一，属于 Oracle 旗下产品。">
    <meta name="keywords" content="docker,containers,tutorial">
    <link rel="stylesheet" type="text/css" href="css/main.css?v=1.29.0">
    <link rel="stylesheet" type="text/css" href="css/tocbot.css?v=1.29.0">
    <link rel="stylesheet" type="text/css" href="css/media.css?v=1.29.0">
    <link rel="stylesheet" type="text/css" href="css/sidebar.css?v=1.29.0">
    <link rel="stylesheet" type="text/css" href="css/copy.css?v=1.29.0">
    <link rel="stylesheet" type="text/css" href="css/demo-preview.css?v=1.29.0">
    <link rel="icon" href="img/logo.svg" type="image/x-icon">
    <script src="js/copy.js?v=1.29.0"></script>
    <script src="js/dark-mode.js?v=1.29.0"></script>
    <script src="js/markdown-style.js?v=1.29.0"></script>
  </head>
  <body id="idoctotop"><a href="#idoctotop" class="gototop">top</a>
    <header class="header">
      <article class="inner warpper"><a class="logo" href="index.html"><svg viewBox="0 0 1280 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
            <path d="M699.88718 472.6h-132.2v-118.8h132.2v118.8z m0-408.6h-132.2v121.4h132.2V64z m156.4 289.6H724.08718v118.8h132.2v-118.8z m-312.6-144.2h-132.2v120.2h132.2v-120.2z m156.2 0h-132.2v120.2h132.2v-120.2z m553.6 200c-28.8-19.4-95.2-26.4-146.2-16.8-6.6-48-33.4-89.8-82.2-127.4l-28-18.6-18.6 28c-36.8 55.6-46.8 147.2-7.4 207.6-17.4 9.4-51.6 22.2-96.8 21.4H4.88718c-17.4 101.6 11.6 233.6 88 324.2 74.2 87.8 185.4 132.4 330.8 132.4 314.8 0 547.8-145 656.8-408.4 42.8 0.8 135.2 0.2 182.6-90.4 3-5 13.2-26.4 17-34.2l-26.6-17.8z m-1022.2-55.8h-132v118.8h132.2v-118.8z m156.2 0h-132.2v118.8h132.2v-118.8z m156.2 0h-132.2v118.8h132.2v-118.8z m-156.2-144.2h-132.2v120.2h132.2v-120.2z" fill="#0187D1"></path>
          </svg>
<span class="title">Docker 入门教程</span></a>
        <div class="content">
          <ul class="menu">
            <li><a href="index.html" target="" class="">Home</a></li>
            <li><a href="https://wangchujiang.com/#/sponsor" target="__blank" class="">Sponsor</a></li>
          </ul><a href="https://github.com/jaywcjlove/docker-tutorial" target="_blank" rel="noopener noreferrer" title="Github" name="Github" class="github"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
              <path d="M9 19c-5 1.5-5-2.5-7-3m14 6v-3.87a3.37 3.37 0 0 0-.94-2.61c3.14-.35 6.44-1.54 6.44-7A5.44 5.44 0 0 0 20 4.77 5.07 5.07 0 0 0 19.91 1S18.73.65 16 2.48a13.38 13.38 0 0 0-7 0C6.27.65 5.09 1 5.09 1A5.07 5.07 0 0 0 5 4.77a5.44 5.44 0 0 0-1.5 3.78c0 5.42 3.3 6.61 6.44 7A3.37 3.37 0 0 0 9 18.13V22"></path>
            </svg></a>
          <dark-mode permanent=""></dark-mode>
        </div>
      </article>
    </header>
    <div class="warpper-content warpper sidebar">
      <div class="sidebar-border">
        <aside class="sidebar" role="navigation">
          <div>
            <a href="index.html" class="">入门</a>
            <label>实践</label>
            <a href="docker-compose.html" class="">Docker Compose</a>
            <a href="elasticsearch.html" class="">ElasticSearch 搜索服务器</a>
            <a href="gitlab/index.html" class="">Gitlab 代码仓库管理系统</a>
            <a href="harbor.html" class="">Harbor</a>
            <a href="mattermost.html" class="">Mattermost 聊天工具</a>
            <a href="mysql.html" class="active">MySQL 数据库</a>
            <a href="nginx.html" class="">Nginx Web 服务器</a>
            <a href="nps/index.html" class="">NPS 内网穿透</a>
            <a href="portainer.html" class="">Portainer Docker 管理</a>
            <a href="postgres.html" class="">PostgreSQL 数据库</a>
            <a href="penpot.html" class="">Penpot 设计和原型</a>
            <a href="navidrome.html" class="">Navidrome 音乐服务器</a>
            <a href="rancher.html" class="">Rancher 容器管理平台</a>
            <a href="redis.html" class="">Redis 数据库</a>
            <a href="rocket.chat/index.html" class="">Rocket.Chat 聊天工具</a>
            <a href="seaweedfs/index.html" class="">SeaweedFS 文件系统</a>
            <a href="sourcegraph/index.html" class="">Sourcegraph 代码搜索引擎</a>
          </div>
        </aside>
      </div>
      <markdown-style theme-auto-switch-disabled="">
        <h1 id="mysql"><a aria-hidden="true" tabindex="-1" href="#mysql" class="anchor"><span class="icon icon-link"></span></a>MySQL</h1>
        <p><a href="https://www.mysql.com/">MySQL</a> 是最流行的关系型数据库管理系统，在 WEB 应用方面 MySQL 是最好的 RDBMS(Relational Database Management System：关系数据库管理系统)应用软件之一，属于 Oracle 旗下产品。</p>
        <h2 id="下载镜像"><a aria-hidden="true" tabindex="-1" href="#下载镜像" class="anchor"><span class="icon icon-link"></span></a>下载镜像</h2>
        <p>拉取官方的镜像，标签为<code>5.7</code>，<a href="https://docs.docker.com/samples/library/mysql/#-via-docker-stack-deploy-or-docker-compose">Docker官方资料</a>、<a href="https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html">MySQL 官方资料</a>，<a href="https://hub.docker.com/_/mysql/">MySQL镜像</a></p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token function">docker</span> pull mysql:5.7.23
</span><span class="code-line line-number" line="2"><span class="token comment"># Trying to pull repository docker.io/library/mysql ...</span>
</span><span class="code-line line-number" line="3"><span class="token comment"># 5.7: Pulling from docker.io/library/mysql</span>
</span><span class="code-line line-number" line="4"><span class="token comment"># 85b1f47fba49: Already exists</span>
</span><span class="code-line line-number" line="5"><span class="token comment"># f34057997f40: Pull complete</span>
</span><span class="code-line line-number" line="6"><span class="token comment"># ....</span>
</span><span class="code-line line-number" line="7"><span class="token comment"># Digest: sha256:bfb22e93ee87c6aab6c1c9a4e70f28fa289f9ffae9fe8e173</span>
</span></code><input type="hidden" value="docker pull mysql:5.7.23
# Trying to pull repository docker.io/library/mysql ...
# 5.7: Pulling from docker.io/library/mysql
# 85b1f47fba49: Already exists
# f34057997f40: Pull complete
# ....
# Digest: sha256:bfb22e93ee87c6aab6c1c9a4e70f28fa289f9ffae9fe8e173
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <h2 id="运行容器示"><a aria-hidden="true" tabindex="-1" href="#运行容器示" class="anchor"><span class="icon icon-link"></span></a>运行容器示</h2>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token function">docker</span> run <span class="token parameter variable">--name</span> mysql <span class="token punctuation">\</span>
</span><span class="code-line line-number" line="2">  <span class="token parameter variable">-p</span> <span class="token number">3306</span>:3306 <span class="token punctuation">\</span>
</span><span class="code-line line-number" line="3">  <span class="token parameter variable">-v</span> <span class="token environment constant">$HOME</span>/_docker/mysql/conf.d:/etc/mysql/conf.d <span class="token punctuation">\</span>
</span><span class="code-line line-number" line="4">  <span class="token parameter variable">-v</span> <span class="token environment constant">$HOME</span>/_docker/mysql/data:/var/lib/mysql <span class="token punctuation">\</span>
</span><span class="code-line line-number" line="5">  <span class="token parameter variable">-v</span> /etc/localtime:/etc/localtime:ro <span class="token punctuation">\</span>
</span><span class="code-line line-number" line="6">  <span class="token parameter variable">-e</span> <span class="token assign-left variable">MYSQL_ROOT_PASSWORD</span><span class="token operator">=</span><span class="token number">123456</span> <span class="token punctuation">\</span>
</span><span class="code-line line-number" line="7">  <span class="token parameter variable">-d</span> mysql:5.7.23
</span></code><input type="hidden" value="docker run --name mysql \
  -p 3306:3306 \
  -v $HOME/_docker/mysql/conf.d:/etc/mysql/conf.d \
  -v $HOME/_docker/mysql/data:/var/lib/mysql \
  -v /etc/localtime:/etc/localtime:ro \
  -e MYSQL_ROOT_PASSWORD=123456 \
  -d mysql:5.7.23
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <ul>
          <li><code>--name mysql</code>：容器名字为 <code>mysql</code></li>
          <li><code>-p 3306:3306</code>：将容器的 3306 端口映射到主机的 3306 端口</li>
          <li><code>-v $HOME/_docker/mysql/conf.d</code>：将主机当前目录下的 <code>~/_docker/mysql/conf.d</code> 挂载到容器的 <code>/etc/mysql/conf.d</code>，这个是挂载配置目录</li>
          <li><code>-v $HOME/_docker/mysql/data</code>：将主机当前目录下的 data 目录挂载到容器的 <code>/var/lib/mysqs</code>，为数据文件存放路径</li>
          <li><code>-e MYSQL_ROOT_PASSWORD=123456</code>：初始化root用户的密码</li>
        </ul>
        <h2 id="查看日志"><a aria-hidden="true" tabindex="-1" href="#查看日志" class="anchor"><span class="icon icon-link"></span></a>查看日志</h2>
        <p>docker exec 命令允许您在 Docker 容器内运行命令。 以下命令行将在 mysql 容器中为您提供一个 bash shell：</p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1">$ <span class="token function">docker</span> <span class="token builtin class-name">exec</span> <span class="token parameter variable">-it</span> mysql <span class="token function">bash</span>
</span></code><input type="hidden" value="$ docker exec -it mysql bash
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>MySQL Server日志可通过 Docker 的容器日志获得：</p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1">$ <span class="token function">docker</span> logs mysql
</span></code><input type="hidden" value="$ docker logs mysql
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <h2 id="修改配置"><a aria-hidden="true" tabindex="-1" href="#修改配置" class="anchor"><span class="icon icon-link"></span></a>修改配置</h2>
        <pre class="language-ini"><code class="language-ini code-highlight"><span class="code-line line-number" line="1"><span class="token comment"># For advice on how to change settings please see</span>
</span><span class="code-line line-number" line="2"><span class="token comment"># http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html</span>
</span><span class="code-line line-number" line="3"><span class="token section"><span class="token punctuation">[</span><span class="token section-name selector">client</span><span class="token punctuation">]</span></span>
</span><span class="code-line line-number" line="4"><span class="token key attr-name">default-character-set</span> <span class="token punctuation">=</span> <span class="token value attr-value">utf8mb4</span>
</span><span class="code-line line-number" line="5">
</span><span class="code-line line-number" line="6"><span class="token section"><span class="token punctuation">[</span><span class="token section-name selector">mysql</span><span class="token punctuation">]</span></span>
</span><span class="code-line line-number" line="7"><span class="token key attr-name">default-character-set</span> <span class="token punctuation">=</span> <span class="token value attr-value">utf8mb4</span>
</span><span class="code-line line-number" line="8">
</span><span class="code-line line-number" line="9"><span class="token section"><span class="token punctuation">[</span><span class="token section-name selector">mysqld</span><span class="token punctuation">]</span></span>
</span><span class="code-line line-number" line="10"><span class="token key attr-name">character-set-client-handshake</span> <span class="token punctuation">=</span> <span class="token value attr-value">FALSE</span>
</span><span class="code-line line-number" line="11"><span class="token key attr-name">character-set-server</span> <span class="token punctuation">=</span> <span class="token value attr-value">utf8mb4</span>
</span><span class="code-line line-number" line="12"><span class="token key attr-name">collation-server</span> <span class="token punctuation">=</span> <span class="token value attr-value">utf8mb4_unicode_ci</span>
</span><span class="code-line line-number" line="13"><span class="token comment"># 忽略数据库表名的大小写区分</span>
</span><span class="code-line line-number" line="14"><span class="token key attr-name">lower_case_table_names</span> <span class="token punctuation">=</span> <span class="token value attr-value">1</span>
</span><span class="code-line line-number" line="15"><span class="token comment"># 解决时区与中国时区不至问题</span>
</span><span class="code-line line-number" line="16"><span class="token key attr-name">default-time_zone</span><span class="token punctuation">=</span><span class="token value attr-value">+8:00</span>
</span><span class="code-line line-number" line="17"><span class="token comment"># 设置服务ID</span>
</span><span class="code-line line-number" line="18"><span class="token key attr-name">server-id</span><span class="token punctuation">=</span><span class="token value attr-value">1</span>
</span><span class="code-line line-number" line="19"><span class="token comment">#</span>
</span><span class="code-line line-number" line="20"><span class="token comment"># Remove leading # and set to the amount of RAM for the most important data</span>
</span><span class="code-line line-number" line="21"><span class="token comment"># cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.</span>
</span><span class="code-line line-number" line="22"><span class="token comment"># innodb_buffer_pool_size = 128M</span>
</span><span class="code-line line-number" line="23"><span class="token comment">#</span>
</span><span class="code-line line-number" line="24"><span class="token comment"># Remove leading # to turn on a very important data integrity option: logging</span>
</span><span class="code-line line-number" line="25"><span class="token comment"># changes to the binary log between backups.</span>
</span><span class="code-line line-number" line="26"><span class="token comment"># log_bin</span>
</span><span class="code-line line-number" line="27"><span class="token comment"># 开启 binlog，log_bin 等于 server-id</span>
</span><span class="code-line line-number" line="28"><span class="token key attr-name">log_bin</span><span class="token punctuation">=</span><span class="token value attr-value">1</span>
</span><span class="code-line line-number" line="29"><span class="token comment">#</span>
</span><span class="code-line line-number" line="30"><span class="token comment"># Remove leading # to set options mainly useful for reporting servers.</span>
</span><span class="code-line line-number" line="31"><span class="token comment"># The server defaults are faster for transactions and fast SELECTs.</span>
</span><span class="code-line line-number" line="32"><span class="token comment"># Adjust sizes as needed, experiment to find the optimal values.</span>
</span><span class="code-line line-number" line="33"><span class="token comment"># join_buffer_size = 128M</span>
</span><span class="code-line line-number" line="34"><span class="token comment"># sort_buffer_size = 2M</span>
</span><span class="code-line line-number" line="35"><span class="token comment"># read_rnd_buffer_size = 2M</span>
</span><span class="code-line line-number" line="36"><span class="token key attr-name">datadir</span><span class="token punctuation">=</span><span class="token value attr-value">/var/lib/mysql</span>
</span><span class="code-line line-number" line="37"><span class="token key attr-name">socket</span><span class="token punctuation">=</span><span class="token value attr-value">/var/lib/mysql/mysql.sock</span>
</span><span class="code-line line-number" line="38">
</span><span class="code-line line-number" line="39"><span class="token comment"># Disabling symbolic-links is recommended to prevent assorted security risks</span>
</span><span class="code-line line-number" line="40"><span class="token key attr-name">symbolic-links</span><span class="token punctuation">=</span><span class="token value attr-value">0</span>
</span><span class="code-line line-number" line="41">
</span><span class="code-line line-number" line="42"><span class="token comment">#log-error=/var/log/mysqld.log</span>
</span><span class="code-line line-number" line="43"><span class="token key attr-name">pid-file</span><span class="token punctuation">=</span><span class="token value attr-value">/var/run/mysqld/mysqld.pid</span>
</span></code><input type="hidden" value="# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[client]
default-character-set = utf8mb4

[mysql]
default-character-set = utf8mb4

[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
# 忽略数据库表名的大小写区分
lower_case_table_names = 1
# 解决时区与中国时区不至问题
default-time_zone=+8:00
# 设置服务ID
server-id=1
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# 开启 binlog，log_bin 等于 server-id
log_bin=1
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

#log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>通过[容器名字]或者[容器 ID]来重启 MySQL，让配置生效。</p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token function">docker</span> restart mysql
</span></code><input type="hidden" value="docker restart mysql
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <h2 id="进入数据库"><a aria-hidden="true" tabindex="-1" href="#进入数据库" class="anchor"><span class="icon icon-link"></span></a>进入数据库</h2>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token comment"># 进入 mysql 容器</span>
</span><span class="code-line line-number" line="2"><span class="token function">docker</span> <span class="token builtin class-name">exec</span> <span class="token parameter variable">-it</span> mysql /bin/bash
</span><span class="code-line line-number" line="3"><span class="token comment"># 通过 mysql 命令登陆</span>
</span><span class="code-line line-number" line="4">mysql <span class="token parameter variable">-uroot</span> <span class="token parameter variable">-p</span>
</span><span class="code-line line-number" line="5">
</span><span class="code-line line-number" line="6"><span class="token comment"># 查看是否开启了binlog</span>
</span><span class="code-line line-number" line="7">show binary logs<span class="token punctuation">;</span>
</span><span class="code-line line-number" line="8">show variables like <span class="token string">'%server_id%'</span><span class="token punctuation">;</span>
</span></code><input type="hidden" value="# 进入 mysql 容器
docker exec -it mysql /bin/bash
# 通过 mysql 命令登陆
mysql -uroot -p

# 查看是否开启了binlog
show binary logs;
show variables like &#x27;%server_id%&#x27;;
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <div class="previous"><a class="prev" href="mattermost.html"><svg viewBox="0 0 1024 1024" width="16" height="16" fill="currentColor">
              <path d="M842.666667 864c-8.533333 0-14.933333-2.133333-21.333334-8.533333l-341.333333-309.333334c-6.4-6.4-10.666667-14.933333-10.666667-23.466666 0-8.533333 4.266667-17.066667 10.666667-23.466667l341.333333-309.333333c12.8-12.8 34.133333-10.666667 44.8 2.133333 12.8 12.8 10.666667 34.133333-2.133333 44.8L548.266667 522.666667l315.733333 285.866666c12.8 10.666667 14.933333 32 2.133333 44.8-6.4 6.4-14.933333 10.666667-23.466666 10.666667z"></path>
              <path d="M512 864c-8.533333 0-14.933333-2.133333-21.333333-8.533333L149.333333 546.133333c-6.4-6.4-10.666667-14.933333-10.666666-23.466666 0-8.533333 4.266667-17.066667 10.666666-23.466667L490.666667 189.866667c12.8-12.8 34.133333-10.666667 44.8 2.133333 12.8 12.8 10.666667 34.133333-2.133334 44.8L217.6 522.666667 533.333333 808.533333c12.8 12.8 14.933333 32 2.133334 44.8-6.4 6.4-14.933333 10.666667-23.466667 10.666667z"></path>
            </svg>
<span>Mattermost 聊天工具
</span></a><a class="next" href="nginx.html"><span>Nginx Web 服务器
</span><svg viewBox="0 0 1024 1024" width="16" height="16" fill="currentColor">
              <path d="M544 522.666667c0-8.533333-4.266667-17.066667-10.666667-23.466667L192 189.866667c-12.8-12.8-34.133333-10.666667-44.8 2.133333-12.8 12.8-10.666667 34.133333 2.133333 44.8l315.733334 285.866667L149.333333 808.533333c-12.8 12.8-14.933333 32-2.133333 44.8 6.4 6.4 14.933333 10.666667 23.466667 10.666667 8.533333 0 14.933333-2.133333 21.333333-8.533333l341.333333-309.333334c6.4-6.4 10.666667-14.933333 10.666667-23.466666z"></path>
              <path d="M864 499.2l-341.333333-309.333333c-12.8-12.8-34.133333-10.666667-44.8 2.133333-12.8 12.8-10.666667 34.133333 2.133333 44.8l315.733333 285.866667-315.733333 285.866666c-12.8 12.8-14.933333 32-2.133333 44.8 6.4 6.4 14.933333 10.666667 23.466666 10.666667 8.533333 0 14.933333-2.133333 21.333334-8.533333l341.333333-309.333334c6.4-6.4 10.666667-14.933333 10.666667-23.466666 0-8.533333-4.266667-17.066667-10.666667-23.466667z"></path>
            </svg></a></div>
        <section class="article-footer"><a href="https://github.com/jaywcjlove/docker-tutorial/tree/master/docs/mysql.md" class="edit-button" target="_blank" rel="noopener noreferrer"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
              <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path>
            </svg>
<span>Edit this page on GitHub</span>
</a><span class="atime">2022/04/20</span></section>
      </markdown-style>
      <nav class="tocs">
        <aside class="inner toc">
          <ol class="tocs-list">
            <li><a href="#下载镜像" class="tocs-link">下载镜像</a></li>
            <li><a href="#运行容器示" class="tocs-link">运行容器示</a></li>
            <li><a href="#查看日志" class="tocs-link">查看日志</a></li>
            <li><a href="#修改配置" class="tocs-link">修改配置</a></li>
            <li><a href="#进入数据库" class="tocs-link">进入数据库</a></li>
          </ol>
        </aside>
      </nav>
    </div>
    <script src="js/demo-preview.js?v=1.29.0"></script>
    <div class="footer warpper">
      <a href="https://wangchujiang.com/#/app" target="_blank">App</a> •
      <a href="https://wangchujiang.com/#/projects" target="_blank">Projects</a> •
      <a href="https://wangchujiang.com/#/sponsor" target="_blank">Sponsor</a> •
      <a href="https://wangchujiang.com/#/app" target="_blank">More Apps</a><br><br>Released under the MIT License. Copyright © 2024 <a href="https://wangchujiang.com/#/about" target="_blank">Kenny Wong</a><br>Generated by <a href="https://github.com/jaywcjlove/idoc" target="_blank">idoc</a> v1.29.0
    </div>
    <script src="js/tocbot.js?v=1.29.0"></script>
  </body>
</html>
